package com.dongdongshop.service.impl;


import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
@DubboService
public class SellerServiceImpl implements SellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public TbSeller getInfo(String sellerId) {
        return tbSellerMapper.selectById(sellerId);
    }

    @Override
    @Transactional
    public Integer add(TbSeller tbSeller) {
        if (tbSellerMapper.selectById(tbSeller.getSellerId()) == null ){
            tbSellerMapper.insertSelective(tbSeller);
            return 1;
        }else{
            return 2;
        }
    }

    @Override
    public Page<TbSeller> findList(Integer pageNum, Integer pageSize,TbSeller tbSeller) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbSeller> tbSeller2 = tbSellerMapper.selectByName(tbSeller);
        PageInfo<TbSeller> pageInfo = new PageInfo(tbSeller2);
        Page<TbSeller> page = new Page(pageInfo.getPageNum(),pageInfo.getPageSize(),pageInfo.getPages(),pageInfo.getList());
        return page;
    }

    @Override
    public TbSeller selectBySellerId(String sellerId) {
        return tbSellerMapper.selectById(sellerId);
    }

    @Override
    public void updateInfo(TbSeller tbSeller) {
        tbSellerMapper.updateByPrimaryKeySelective(tbSeller);
    }
}
